package com.example.demo.controller;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.entity.SynRecord;
import com.example.demo.mysqlDao.MysDao;
import com.example.demo.response.JsonData;
import com.example.demo.service.AsyncService;
import com.example.demo.service.SynRecordService;
import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Map;

@Controller
//@EnableAsync
public class TestController {

    @Autowired
    private AsyncService asyncService;

    private final Logger logger = LoggerFactory.getLogger(TestController.class);
    @Autowired
    private SynRecordService  recordService;

    @RequestMapping(value = "/import", method = RequestMethod.GET)
    public String test(HttpServletRequest request) {

      return "import";
    }



    /**
     * 首页跳转
     * @author   whh
     * @param
     * @return      java.lang.String
     * @exception
     * @date        2020/6/16 10:32
     */
    @RequestMapping({"/layuiModel","/"})
    public String demo() {
        return "layuiModel";
    }


    @RequestMapping(value = "/success", method = RequestMethod.GET)
    public String success() {

        return "success";
    }

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String test1() {

        return "import";
    }

    //测试同步
//    @RequestMapping(value = "/testSync")
//    @ResponseBody
//    public String testSync()throws InterruptedException {
//
//        System.out.println("当前线程名："+Thread.currentThread().getName());
//        LocalTime time1 = LocalDateTime.now().toLocalTime();
//        System.out.println("第一次调用时间："+ time1);
//
//        Thread.sleep(4000);//此时需要处理一个InterruptedException异常
//        LocalTime time2 = LocalDateTime.now().toLocalTime();
//        System.out.println("第二次调用时间："+ time2);
//
//        //得出两个时间差
//        Duration duration = Duration.between(time1,time2);
//        long timeC = duration.toMillis();
//        System.out.println("两者相差："+ (timeC/1000)+"秒");
//
//        return "666666";
//    }

//    //测试异步
//    @RequestMapping(value = "/testAsync")
//    @ResponseBody
//    public String testAsync()throws InterruptedException {
//
//        System.out.println("controller当前线程名："+Thread.currentThread().getName());
//        LocalTime time1 = LocalDateTime.now().toLocalTime();
//        System.out.println("第一次调用时间："+ time1);
//
//        Thread thread = new Thread(new TestAsync());
//        thread.start();
////        Thread.sleep(4000);//此时需要处理一个InterruptedException异常
//        LocalTime time2 = LocalDateTime.now().toLocalTime();
//        System.out.println("第二次调用时间："+ time2);
//        //得出两个时间差
//        Duration duration = Duration.between(time1,time2);
//        long timeC = duration.toMillis();
//        System.out.println("1号结果两者相差："+ (timeC/1000)+"秒");
//
//        return "666666";
//    }

    //测试异步 注解方式
    @RequestMapping(value = "/testAsyncZhuJie")
    @ResponseBody
    public String testAsyncZhuJie()throws InterruptedException {

        System.out.println("controller中当前线程名："+Thread.currentThread().getName());
        LocalTime time1 = LocalDateTime.now().toLocalTime();
        System.out.println("controller中第一次调用时间："+ time1);

        //业务调用
        asyncService.testAsyncZhuJie();
//        Thread.sleep(4000);//此时需要处理一个InterruptedException异常
        LocalTime time2 = LocalDateTime.now().toLocalTime();
        System.out.println("controller中第二次调用时间："+ time2);
        //得出两个时间差
        Duration duration = Duration.between(time1,time2);
        long timeC = duration.toMillis();
        System.out.println("controller中1号结果两者相差："+ (timeC/1000)+"秒");

        return "666666";
    }


//    @RequestMapping(value = "/test", method = RequestMethod.GET)
//    public String test(){
//        System.out.println("进来了------");
//        return "Index";
//    }


//    @RequestMapping(value = "/success", method = RequestMethod.GET)
//    public String success(){
//        return "success";
//    }
//
//    @RequestMapping(value = "/test1", method = RequestMethod.POST)
//    public  @ResponseBody CommonResponseDto test(@RequestBody String request){
//        TestRequestDto requestDto = JSONObject.parseObject(request, TestRequestDto.class);
//        System.out.println(requestDto);
//        return new CommonResponseDto().code(0).success(true);
//    }

















































//    @RequestMapping(value = "/test1",method= RequestMethod.GET)
//    public String test() {
//
//        System.out.println("进来了------");
//        return "Index";
//    }
}
